// 假设存在这个文件
export default {
  namespaced: true,
  state: {
    currentProduct: null,
    recentViewed: [] // 最近浏览
  },
  mutations: {
    SET_CURRENT_PRODUCT(state, product) {
      state.currentProduct = product;
    },
    ADD_RECENT_VIEWED(state, product) {
      // 添加到最近浏览，避免重复
      const exists = state.recentViewed.some(item => item.id === product.id);
      if (!exists) {
        state.recentViewed.unshift(product);
        // 限制最近浏览数量
        if (state.recentViewed.length > 10) {
          state.recentViewed.pop();
        }
      }
    }
  },
  actions: {
    // 可以在这里处理异步操作
    setCurrentProduct({ commit }, product) {
      commit('SET_CURRENT_PRODUCT', product);
      commit('ADD_RECENT_VIEWED', product);
    }
  }
}
